<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #box{
            width: 800px;
            margin: 0 auto;
            margin-top: 80px;
        }
        #box li{
            list-style: none;
            line-height: 45px;
            border-bottom: 1px solid #ccc;
        }
        #box li span:nth-of-type(1){
            margin-left: 40px;
        }
        #box li span:nth-of-type(3){
            float: right;
        }
    </style>
</head>

<body>
    <div id="box">
        <ul>
            <li v-for='(item,index) in arr'>
                <span> </span>
                <span>{{item.title}}</span>
                <span>{{item.create_at | formatDate}}</span>
            </li>
        </ul>
    </div>
    <script src="./js/vue.js"></script>
    <script src="./js/vue-resource.js"></script>
    <script src="./js/axios.min.js"></script>
    <script>
          // 月份、日期、小时等小于10前面补0
          let padDate = (value => {
            return value < 10 ? '0' + value : value;
        })
        let vm = new Vue({
            el: "#box",
            data: {
                arr: [],
            },
            beforeCreate() {
                axios.get('https://cnodejs.org/api/v1/topics', )
                .then(res=>{
                    console.log("结果:",res.data);
                    this.arr = res.data.data; // 请求数据
                }).catch(err => {
                    console.log(err);
                })
            },
            filters: {
                formatDate: (value => {
                    let date = new Date(value);
                    let year = date.getFullYear();
                    let month = padDate(date.getMonth() + 1);
                    let day = padDate(date.getDate());
                    let hours = padDate(date.getHours());
                    let minutes = padDate(date.getMinutes());
                    let seconds = padDate(date.getSeconds());
                    return year + '-' + month + '-' + day + '-' + ' ' + hours + ':' + minutes + ':' + seconds;
                })
            },
        })
    </script>
</body>

</html>